package com.infosys.china.config;

import com.infosys.china.bean.User;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;


import javax.annotation.Resource;

/**
 * @author Administrator
 */
@CanalTable("user")
@Component
public class UserHandler implements EntryHandler<User> {

    @Resource
    RedisTemplate<String, Object> redisTemplate;

    private    static final String  USER = "user:";
    @Override
    public void insert(User user) {
        System.out.println("新增用户");
        System.out.println("user = " + user);
        redisTemplate.opsForValue().set(USER+user.getId(), user);
    }

    @Override
    public void update(User before, User after) {
        System.out.println("修改用户");
        System.out.println("修改用户before：" + before);
        System.out.println("修改用户after：" + after);
        redisTemplate.opsForValue().set(USER+after.getId(), after);
    }

    @Override
    public void delete(User user) {
        System.out.println("删除用户user = " + user);
        redisTemplate.delete(USER+user.getId());
    }

    public static void main(String[] args) {
        Integer i =1;
        String s ="1";
        if(i.toString().equals(s)){
            System.out.println("true");
        }
    }

}